package com.bear.hospital.service.admin.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bear.hospital.mapper.AdminMapper;
import com.bear.hospital.mapper.ApiLogMapper;
import com.bear.hospital.pojo.Admin;
import com.bear.hospital.pojo.ApiLog;
import com.bear.hospital.pojo.Orders;
import com.bear.hospital.service.admin.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("AdminService")
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;
    @Resource
    ApiLogMapper apiLogMapper;

    /**
     * 登录数据校验
     */
    @Override
    public Admin login(String aId, String aPassword) {
        Admin admin = this.adminMapper.selectById(aId);
        if (admin == null) {
            return null;
        } else {
            if ((admin.getAPassword()).equals(aPassword)) {
                return admin;
            }
        }
        return null;
    }

    @Override
    public Map<String, Object> LogQuery(int pageNumber, int size, String query) {
        Page<ApiLog> page = new Page<>(pageNumber, size);
        QueryWrapper<ApiLog> wrapper = new QueryWrapper<>();
        wrapper.eq("dr", "0");
      //  wrapper.like("name", query);
        IPage<ApiLog> iPage = this.apiLogMapper.selectPage(page, wrapper);
        List<ApiLog> log=apiLogMapper.selectList(wrapper);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("total", iPage.getTotal());       //总条数
        hashMap.put("pages", iPage.getPages());       //总页数
        hashMap.put("pageNumber", iPage.getCurrent());//当前页
        hashMap.put("log", iPage.getRecords()); //查询到的记录
        return hashMap;

    }


}
